/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.cashmate.struts;

import com.cashmate.hibernate.dao.MatrixcategoriesCriteriaDAO;
import com.cashmate.hibernate.dao.MatrixcategoriesDAO;
import com.cashmate.hibernate.dao.MatrixcriteriaDAO;
import com.cashmate.hibernate.pojo.Branches;
import com.cashmate.hibernate.pojo.Matrixcategories;
import com.cashmate.hibernate.pojo.MatrixcategoriesCriteria;
import com.cashmate.hibernate.pojo.Matrixcriteria;
import com.opensymphony.xwork2.ActionSupport;
import java.util.ArrayList;
import java.util.List;
import org.apache.log4j.Logger;
import org.apache.struts2.ServletActionContext;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;

/**
 *
 * @author Dine
 */
public class GetCategInfo extends ActionSupport {

    private static Logger logger = Logger.getLogger(GetAreas.class);
    private MatrixcategoriesDAO mdao = (MatrixcategoriesDAO) ServletActionContext.getServletContext().getAttribute("matrixcategoriesDAO");
    private MatrixcriteriaDAO mcrd = (MatrixcriteriaDAO) ServletActionContext.getServletContext().getAttribute("matrixcriteriaDAO");
    private MatrixcategoriesCriteriaDAO mccd = (MatrixcategoriesCriteriaDAO) ServletActionContext.getServletContext().getAttribute("matrixcategoriesCriteriaDAO");
    private Matrixcategories category;
    private List<Matrixcriteria> listCriterias;
    private int perfectrating;
    private String matrixcategidparam;

    public Matrixcategories getCategory() {
        return category;
    }

    public List<Matrixcriteria> getListCriterias() {
        return listCriterias;
    }

    public int getPerfectrating() {
        return perfectrating;
    }
    
    public void setMatrixcategidparam(String matrixcategidparam) {
        this.matrixcategidparam = matrixcategidparam;
    }

    @Action(value = "/get-matrixcateginfo", results = {
        @Result(name = "success", location = "../../loanapplication.jsp")
    })
    public String getCategories() {
        try {
            Branches b = (Branches) ServletActionContext.getRequest().getSession().getAttribute("branch");
            int id = Integer.parseInt(matrixcategidparam) + 1;
//            System.out.println("MCID:" + id);
            category = mdao.get(id);
            perfectrating = 0;
            listCriterias = new ArrayList<Matrixcriteria>();
            List<MatrixcategoriesCriteria> matrixcrit = mccd.getCriteriasPerCategory(id);
//            System.out.println("matrixcrit1: " + matrixcrit);
            for (int s = 0; s < matrixcrit.size(); s++) {
                int critid = matrixcrit.get(s).getMatrixcategoriesCriteriaid();
                Matrixcriteria mcrit = mcrd.get(critid);
//                System.out.println(mcrit.getCriterianame());
                perfectrating = perfectrating+mcrit.getTotalvalue();
                listCriterias.add(mcrit);
            }
//            System.out.println("matrixcrit2: " + matrixcrit);
//            System.out.println("perfrating:" + perfectrating);


            return SUCCESS;

        } catch (Exception e) {
        }
        return SUCCESS;
    }
}
